﻿@model cloudscribe.Core.IdentityServerIntegration.Models.ClientItemViewModel
@using cloudscribe.Core.IdentityServerIntegration.Models;
@using cloudscribe.Core.IdentityServerIntegration
@inject IStringLocalizer<CloudscribeIds4Resources> sr
@{
    var secretIndex = 0;
}

<h3 class="mt-3">@sr["Client Secrets"] </h3>
@{ await Html.RenderPartialAsync("AddClientSecretPartial", new NewClientSecretViewModel(Model.SiteId, Model.ClientId));}
@if (Model.Client.ClientSecrets.Count > 0)
{
    <table class="table table-striped">
        <tr>
            <th></th>
            <th>
                @sr["Value"]
            </th>
            <th>
                @sr["Description"]
            </th>
            <th>
                @sr["Expiration"]
            </th>
            <th>
                @sr["Type"]
            </th>
        </tr>
        @foreach (var c in Model.Client.ClientSecrets)
        {
            <tr>
                <td>
                    <button type="button" class="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="@("#confirmDeleteSecretModal" + secretIndex)">
                        @sr["Delete"]
                    </button>
                    <form asp-controller="Clients" asp-action="DeleteClientSecret">
                        <input asp-for="SiteId" type="hidden" />
                        <input name="ClientId" value="@Model.ClientId" type="hidden" />
                        <input name="SecretValue" value="@c.Value" type="hidden" />
                        <div class="modal fade" id="@("confirmDeleteSecretModal" + secretIndex)" tabindex="-1" role="dialog" aria-labelledby="@("confirmDeleteSecretHeading" + secretIndex)">
                            <div class="modal-dialog modal-sm" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h4 class="modal-title" id="@("confirmDeleteSecretHeading" + secretIndex)">@sr["Confirm Delete"]</h4>
                                        <button type="button" data-bs-dismiss="modal" class="btn-close" aria-label='@sr["Close"]'></button>
                                    </div>
                                    <div class="modal-body">
                                        @string.Format(sr["Are you sure you want to delete the secret {0}?"], c.Value)
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-primary" data-bs-dismiss="modal">@sr["Cancel"]</button>
                                        <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </td>
                <td>@c.Value</td>
                <td>@c.Description</td>
                <td>@(c.Expiration?.ToString("d", CultureInfo.CurrentCulture))</td>
                <td>@c.Type</td>
            </tr>
            {
                secretIndex += 1;
            }
        }
    </table>
}
